﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Xcelligent.HyperR
{
    public partial class Home : Form
    {
        public Home()
        {
            InitializeComponent();
        }

        #region Properties

        public string VMDirectory
        { get { return RecoverPathTextBox.Text; } }


        #endregion


        #region Event Handlers

        private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Quit();
        }

        private void CustomVMDirectoryCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (!CustomVMDirectoryCheckBox.Checked)
                CustomVMDirectoryTextBox.Text = global::Xcelligent.HyperR.Properties.Settings.Default.DefaultVMDirectory;
        }

        private void CustomVMBrowseButton_Click(object sender, EventArgs e)
        {
            DialogResult CustomVMDialogResult = CustomVMFolderBrowserDialog.ShowDialog();
            if (CustomVMDialogResult == DialogResult.OK)
                CustomVMDirectoryTextBox.Text = CustomVMFolderBrowserDialog.SelectedPath;
        }

        private void RecoverPathButton_Click(object sender, EventArgs e)
        {
            DialogResult RecoverVMDialogResult = RecoverVMFolderBrowserDialog.ShowDialog();
            if (RecoverVMDialogResult == DialogResult.OK)
                RecoverPathTextBox.Text = RecoverVMFolderBrowserDialog.SelectedPath;
        }

        private void CancelButton_Click(object sender, EventArgs e)
        {
            Quit();
        }

        private void RecoverPathTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        #endregion


        #region Helper Methods

        private void Quit()
        {
            if (Application.AllowQuit)
            {
                try { Application.Exit(); }
                catch { Error("Failed to quit"); }
            }
        }
        
        private void Error(string Message)
        {
            // Just display a generic error for the time. In the
            // future develop extremely complex message system and
            // propose its use with constant strings in wrist watches.
            MessageBox.Show(string.Format("Error: {0}", Message));
        }

        private bool IsValid(string VMPath)
        {

            return true;
        }

        #endregion

        private void RecoverButton_Click(object sender, EventArgs e)
        {
            if (!System.IO.Directory.Exists(VMDirectory))
                return;

            RecoveryUtility RU = new RecoveryUtility(VMDirectory);
            System.Console.Write("mklink /?");
            System.Console.Read();
        }


    }
}
